<?php

namespace app\common\model;

use WeChat\Contracts\Tools;

class User extends BaseModel
{
    protected $table = 'user';
    public function getNickNameAttr($val)
    {
        return Tools::emojiDecode($val);
    }
    public function setNickNameAttr($val)
    {
        return Tools::emojiEncode($val);
    }
    public function getSearchTipAttr($val,$data){
        return $data['nickname'].' '.$data['phone'];
    }

    public function level(){
        return $this->hasOne(ShopStudyCate::class,'id','grade_id');
    }

    public function store(){
        return $this->hasOne(ShopStore::class,'id','store_id');
    }

    public function originalStore(){
        return $this->hasOne(ShopStore::class,'id','original_store_id');
    }

    public function member(){
        return $this->hasMany(ShopMember::class,'uid','id');
    }

    public function usermember(){
        return $this->hasMany(ShopMember::class,'uid','id')->where('expire_time',">",time());
    }

    public function userCard(){
        return $this->hasMany('ShopMember','id');
    }

}
